<template>
	<!-- 添加集采单 -->
	<div class="page" v-loading="loading">
		<el-breadcrumb class="breadcrumb" separator-class="el-icon-arrow-right">
			<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
			<el-breadcrumb-item>添加集采单</el-breadcrumb-item>
		</el-breadcrumb>
		<el-form class="content" ref="form" :model="form" status-icon :rules="rules" label-width="120px">
			
			<el-form-item label="单据编号" prop="receiptNumber">
				<el-input size="small" v-model="form.receiptNumber"></el-input>
			</el-form-item>
			
			<el-form-item label="发票编号">
				<el-input size="small" v-model="form.invoiceNumber"></el-input>
			</el-form-item>
			<el-form-item label="收付款凭证号">
				<el-input size="small" v-model="form.paymentNumber"></el-input>
			</el-form-item>

			<select-one-supplier v-on:sendGoodsData="getSupplierData" :type="suType" :bet="suType"></select-one-supplier>
			<select-more-goods v-on:sendSomeGoodsData="getMoreGoodsData" ref="moreGoods"></select-more-goods>

			<el-form-item label="备注">
				<el-input size="small" v-model="form.remark"></el-input>
			</el-form-item>
			<!-- <el-form-item label="仓库名称" prop="warehouseName">
				<el-input size="small" v-model="form.warehouseName"></el-input>
			</el-form-item> -->
			<el-form-item>
				<el-button size="small" type="primary" @click="submitForm('form')">立即创建</el-button>
				<el-button size="small" @click="utils.back">取消</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>
<script>
import axios from 'axios';
import cityThree from '../../common/cityThree.vue';
import selectOneSupplier from '../../common/selectOneSupplier.vue';
import selectMoreGoods from '../../common/selectMoreGoods.vue';
export default {
	name: "add",
	data() {
		return {
			suType:'INVESTOR',
			form: {
				"invoiceNumber": "",		//发票编号
				"paymentNumber": "",		//收付款凭证号
				"qty": 1,					//数量
				"receiptNumber": "",		//单据编号
				"stockInType": "PRESALELIS",	//类型
				"supplierContact": "0",	//供应商联系人
				"supplierId": 0,			//供应商Id
				"supplierMobile": "",		//供应商手机
				"supplierName": "",		//供应商
				"remark": "",				//备注
				"stockInItems": [],
			},
			rules: {
				amount: [{required: true,message: '金额不能为空',trigger: 'blur'}],
				qty: [{required: true,message: '数量不能为空',trigger: 'blur'}],
				receiptNumber: [{required: true,message: '单据编号不能为空',trigger: 'blur'}],
				stockInType: [{required: true,message: '类型不能为空',trigger: 'blur'}],
				packQty: [{required: true,message: '件数不能为空',trigger: 'blur'}],
				warehouseName: [{required: true,message: '仓库不能为空',trigger: 'blur'}],
			},
			loading: false,
			city: ''
		}
	},
	components: {
		cityThree,
		selectOneSupplier,
		selectMoreGoods
	},
	created() { 
		this.form.stockInItems = [];
	},
	methods: {
		// 获取子组件（选择商品）数据
		getMoreGoodsData(data){
			console.log(data,this.form.stockInItems)
			for(var i in data){
				this.form.stockInItems.push(data[i]);
			}
		},
		// 获取子组件（选择供应商）数据
		getSupplierData(dataID,data){
			let item = data[0];
			this.form.supplierContact = item.name;
			this.form.supplierId = dataID;
			this.form.supplierMobile = data[0].mobile;		//供应商手机
			this.form.supplierName = data[0].supplierName;
		},
		// 添加进货单
		submitForm(formName) {
			this.loading = true;
			this.$refs[formName].validate((valid) => {
				if (valid) {
					this.$refs.moreGoods.sendData();
					this.$post("stockInAdd", this.form).then((res) => {
						this.loading = false;
						if (res.code == 200) {
							this.$msg.success("添加成功～");
							this.$router.back();
						} else {
							this.$msg.warning(res.message);
						}
					})
				} else {
					this.$msg.error("网络或服务器错误");
					this.loading = false;
				}
				this.form.stockInItems = [];
			});
		},
	}
};
</script>
<style lang="less" scoped>
.page {
  .content {
    width: 1000px;
    margin: 0 auto;
    .el-input {
      width: 600px;
    }
    .add-data {
      .el-input {
        width: 80%;
      }
    }
  }
}
</style>